﻿/// <reference path="../Base/jquery-1.7.1.js" />
/// <reference path="../PageHelper/swfupload.queue.js" />
/// <reference path="../PageHelper/swfupload.js" />

/*
 * @Description:楼盘详情页面js
 * @Author:yangpl
 * @Date:2014-08-18
 */

var pageNewEstateDetail = {};

function setPageStartTime() {
    window.pageStartTime = new Date();
}
function setPageEndTime() {
    $("#timeCount").html("查询耗时" + timehelper.TimeDiffirence(window.pageStartTime, new Date()).msDiff + "毫秒");
}

pageNewEstateDetail.init = function () {
    /// <summary>楼盘详情页初始化</summary>
    var option = {
        titleID: "titleid",
        contentID: "contentdiv",
        currentClassName: "current",
        titleFun: pageNewEstateDetail.getTitles,
        urlFun: pageNewEstateDetail.getTabUrl,
        dataFun: pageNewEstateDetail.getData,
        contentFun: null
    };
    tabHelper(option);

    //栋座搜索智能提示
    pageNewEstateDetail.searchBuildingAutoMatch($("#hidEstateKeyId").val());
};

pageNewEstateDetail.getTitles = function () {
    //return ["基本信息", "周边设施", "小区图片"];
    return ["基本信息",  "小区图片"];
};

pageNewEstateDetail.getTabUrl = function (tabname) {
    var urlNum = window.location.href.split('=')[1];
    if (tabname == "基本信息") {

        return "/estate/get-estate-base-info?KeyId=" + urlNum;
    }
    //if (tabname == "周边设施") {
    //    return "/estate/find-estate-around-for-view-new?KeyId=" + urlNum;
    //}
    if (tabname == "小区图片") {
        return "/estate/find-estate-photo-for-view?EstateKeyId=" + urlNum + "&PhotoType=1&EstateName=" + escape($("#spanEstateName").html());
    }
};

pageNewEstateDetail.getData = function (tabname) {
    if (tabname != "栋座") {
        return null;
    } else {
        return [{ name: "key", value: tabname }];
    }
};

//栋座操作按钮样式变化
pageNewEstateDetail.buildingOperateChange = function () {
    var checkedCount = 0;
    $("#gdList input[building-check-box=buildingCheckBox]").each(function () {
        if ($(this).attr("checked") == "checked") {
            checkedCount = checkedCount + 1;
        }
    });

    if (checkedCount == 1) {
        $("#btnDelBuildingData,#btnBatchSet,#btnBatchSetCancel,#btnTransferBuild,#btnMerge").addClass("btn-blue").removeClass("edit-btn-gray");
    } else {
        $("#btnDelBuildingData,#btnBatchSet,#btnBatchSetCancel,#btnTransferBuild,#btnMerge").removeClass("btn-blue").addClass("edit-btn-gray");
    }

    if (checkedCount > 1) {
        $("#btnDelBuildingData,#btnBatchSet,#btnBatchSetCancel,#btnTransferBuild,#btnMerge").addClass("btn-blue").removeClass("edit-btn-gray");
    }

    if (checkedCount < 1) {
        $("#btnDelBuildingData,#btnBatchSet,#btnBatchSetCancel,#btnTransferBuild,#btnMerge").removeClass("btn-blue").addClass("edit-btn-gray");
    }
}

//栋座搜索智能提示
pageNewEstateDetail.searchBuildingAutoMatch = function (estateKeyId) {
    /// <summary>栋座搜索智能提示</summary>
    /// <param name="estateKeyId" type="String">楼盘KeyId</param>
    //栋座搜索智能提示Url
    pageNewEstateDetail.getBuildingUrl = function () {
        return "/Estate/auto-match-building-name?EstateKeyId=" + estateKeyId + "&BuildingName=" + escape($("#txtBuildingName").val());
    };
    //楼盘自动完成及赋值隐藏域
    $("#txtBuildingName").autocomplete(pageNewEstateDetail.getBuildingUrl, {
        width: 100,
        max: 1000,
        Default: 1,
        selectFirst: false,
        cacheLength: 0,
        formatItem: function (row) {
            return row.ItemText;
        },
        formatResult: function (row) {
            return row.ItemText;
        }
    });
};

//搜索栋座
pageNewEstateDetail.searchBuilding = function (estateKeyId) {
    $("#btnSearchBuilding").unbind("click");
    $("#btnSearchBuilding").bind("click", function () {
        var reqData = {
            "KeyId": estateKeyId,
            "BuildingName": $("#txtBuildingName").val()
        };
        $.AjaxAgency("/estate/find-estate-for-view", reqData, function (data) {
            if (data.indexOf("#error:") > -1) {
                $.OKDialogAgency('<center>加载失败，请重新加载!</center>');
            } else {
                $("#ajaxPages .pages").remove();
                $(data).replaceAll("#gdList");
            }
        });
    });
};

//栋座分页时要初始化数据
pageNewEstateDetail.buildingPartialInit = function () {
    //工具栏按钮状态处理
    //if ($("#hidLockFlag").val() == "1") {
    //    if ($("#hidNoLockPermisstion").val() == "0") {
    //        $("#btnAddBuilding").removeClass("btn-blue").addClass("edit-btn-gray").bind("click", function () {
    //            return false;
    //        });
    //    }
    //    $("#btnDelBuildingData,#btnBatchSet,#btnBatchSetCancel,#btnTransferBuild,#btnMerge").removeClass("btn-blue").addClass("edit-btn-gray").bind("click", function () {
    //        return false;
    //    });
    //    $("#gdList .editBuilding").addClass("disabled").bind("click", function () {
    //        return false;
    //    });
    //    //全选
    //    other.selectAll("#chbSelectAll", "#gdList .btnValues");
    //    ////栋座搜索
    //    //pageNewEstateDetail.searchBuilding($("#hidEstateKeyId").val());
    //    return;
    //}

    //全选
    other.selectAll("#chbSelectAll", "#gdList .btnValues", pageNewEstateDetail.buildingOperateChange);

    $("#gdList input[building-check-box=buildingCheckBox],#chbSelectAll").removeAttr("checked");
    $("#btnDelBuildingData,#btnBatchSet,#btnBatchSetCancel,#btnTransferBuild,#btnMerge").removeClass("btn-blue").addClass("edit-btn-gray");
    $("#ajaxPages").delegate("input[building-check-box=buildingCheckBox]", "click", pageNewEstateDetail.buildingOperateChange);

    $("#gdList .editBuilding").unbind("click");
    $("#gdList .editBuilding").click(function () {
        var tempBuildingKeyId = $(this).attr("keyid");
        var tempBuildingCode = $(this).attr("currentcode");

        var reqData = { "KeyId": tempBuildingKeyId };
        $.AjaxAgency("/estate/find-building-for-edit", reqData, function (data) {
            if (data.indexOf("#error:") == -1) {
                $.dialog({
                    id: "dialogEditBuildingInfo",
                    lock: true,
                    title: "编辑栋座",
                    content: data
                });
            } else {
                $.dialog({
                    lock: true,
                    background: "#808080",
                    opacity: 0.87,
                    content: data,
                    cancel: function () { }
                });
            }
        });
    });

    //批量设置
    $("#btnBatchSet").unbind("click");
    $("#btnBatchSet").bind("click", function () {
        var objModel = other.checkCount(true, "#ajaxPages input[class=btnValues]:checked", "未选中任何信息！", "选中信息必须唯一！");
        if (objModel == false) {
            return false;
        }

        if ($("#ulBatchSetItem").is(":hidden")) {
            $("#ulBatchSetItem").css("display", "block");
            other.showAndHide("#btnBatchSet", "ulBatchSetItem");
            $(this).find("i").addClass("icon-statusModify-on");
        } else {
            $("#ulBatchSetItem").css("display", "none");
            $(document).unbind("click");
            $(this).find("i").removeClass("icon-statusModify-on");
        }

    });

    $("#btnBatchSetCancel").unbind("click");
    $("#btnBatchSetCancel").bind("click", function () {
        var objModel = other.checkCount(true, "#ajaxPages input[class=btnValues]:checked", "未选中任何信息！", "选中信息必须唯一！");
        if (objModel == false) {
            return false;
        }

        if ($("#ulBatchSetItemCancel").is(":hidden")) {
            $("#ulBatchSetItemCancel").css("display", "block");
            other.showAndHide("#btnBatchSetCancel", "ulBatchSetItemCancel");
            $(this).find("i").addClass("icon-statusModify-on");
        } else {
            $("#ulBatchSetItemCancel").css("display", "none");
            $(document).unbind("click");
            $(this).find("i").removeClass("icon-statusModify-on");
        }

    });


    //批量删除
    $("#btnDelBuildingData").unbind("click");
    $("#btnDelBuildingData").bind("click", function () {
        var objModel = other.checkCount(true, "#ajaxPages input[class=btnValues]:checked", "请选择信息！", "选择信息必须唯一！");
        if (objModel == false) {
            return false;
        }
        var tempKeyIds = "";
        $("#ajaxPages input[class=btnValues]:checked").each(function () {
            tempKeyIds += $(this).attr("keyid") + ",";
        });
        tempKeyIds = tempKeyIds.substring(0, tempKeyIds.length - 1);
        //删除弹框
        $.dialog({
            id: "dialogDelBuilding",
            title: "删除栋座",
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: '<center>您确定要删除选中的信息吗？</center>',
            ok: function () {
                var reqData = {
                    "KeyIds": tempKeyIds
                };
                $.AjaxAgency("/estate/batch-remove-building", reqData, function (data) {
                    if (data == "ok") {
                        $.OKDialogAgency('<center>删除成功！</center>', "提示", function () {
                            window.location.href = window.location.href.split("#")[0];
                        }, function () {
                            window.location.href = window.location.href.split("#")[0];
                        });

                        art.dialog.get("dialogDelBuilding").close();

                    } else {
                        $.OKDialogAgency('<center>' + data + '</center>');
                    }
                });
                return false;
            },
            cancel: true
        });
    });

    //批量转移栋座
    $("#btnTransferBuild").unbind("click");
    $("#btnTransferBuild").bind("click", function () {
        var objModel = other.checkCount(true, "#ajaxPages input[class=btnValues]:checked", "请选择要转移信息！", "选择信息必须唯一！");
        if (objModel == false) {
            return false;
        }
        var tempKeyIds = "";
        $("#ajaxPages input[class=btnValues]:checked").each(function () {
            tempKeyIds += $(this).attr("keyid") + ",";
        });
        tempKeyIds = tempKeyIds.substring(0, tempKeyIds.length - 1);
        //转移栋座弹框
        $.dialog({
            id: "dialogTransferBuild",
            title: "转移栋座",
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: '<span id="spanTransferBuild">' + $("#divTransferBuild").html() + '</span>',
            init: function () {
                var tempDistrict = $("#spanTransferBuild [districts=Districts]"), tempTransferBuidName = $("#spanTransferBuild input[transfer-buid=txtTransferBuidName]"), tempEstateName = "请输入楼盘名", tempTargetEstateKeyId = $("#spanTransferBuild input[name=TargetEstateKeyId]"), tempBtnSubmit = $("#spanTransferBuild input[btn-submit=1]");

                tempDistrict.change(function () {
                    tempTransferBuidName.val(tempEstateName);
                    tempTargetEstateKeyId.val("");
                    $("#spanTransferBuild input[btn-submit=1]").removeClass("btn-red").addClass("btn-gray");
                });

                tempTransferBuidName.focus(function () {
                    var $TempCurrentEleTxt = $(this);
                    if (tempDistrict.val() == "-1") {
                        $TempCurrentEleTxt.after(agencyVerify.greatErrorHtml($TempCurrentEleTxt, "请先选择行政区"));
                    }
                    if ($TempCurrentEleTxt.val() == tempEstateName) {
                        $TempCurrentEleTxt.val("");
                    }
                }).blur(function () {
                    $(this).next("span[class=wrong]").remove();
                    if (!other.trim($(this).val())) {
                        $(this).val(tempEstateName);
                        tempTargetEstateKeyId.val("");
                    }
                });

                $(tempTransferBuidName).autocomplete(function () {
                    if (tempDistrict.val() == "-1") {
                        return "";
                    } else {
                        return "/estate/AutoEstate?DistrictKeyId=" + tempDistrict.val() + "&EstateName=" + escape(tempTransferBuidName.val());
                    }

                }, {
                    width: 260,
                    max: 12,
                    selectFirst: false,
                    cacheLength: 0,
                    formatItem: function (row) {
                        if (row.EstateFullName != null && row.EstateFullName != "") {
                            return row.EstateFullName;
                        } else {
                            return row.EstateFullName;
                        }
                    },
                    formatResult: function (row) {
                        return row.EstateName;
                    }
                }).result(function (a, b) {
                    $(tempTargetEstateKeyId).val(b.KeyId);
                    $("#spanTransferBuild input[btn-submit=1]").removeClass("btn-gray").addClass("btn-red");
                });

                tempTransferBuidName.change(function () {
                    tempTargetEstateKeyId.val("");
                    $("#spanTransferBuild input[btn-submit=1]").removeClass("btn-red").addClass("btn-gray");
                });

                tempBtnSubmit.click(function () {
                    if (tempBtnSubmit.hasClass("btn-red")) {
                        var reqData = {
                            "BuildingKeyIds": tempKeyIds,
                            "OriginEstateKeyId": $("#spanTransferBuild input[name=OriginEstateKeyId]").val(),
                            "TargetEstateKeyId": tempTargetEstateKeyId.val()
                        };
                        $.AjaxAgency("/estate/batch-transfer-building", reqData, function (data) {
                            if (data == "ok") {
                                $.OKDialogAgency('<center>栋座转移成功！</center>', '提示', function () {
                                    window.location.href = window.location.href.split("#")[0];
                                }, function () {
                                    window.location.href = window.location.href.split("#")[0];
                                });

                                art.dialog.get('dialogTransferBuild').close();

                            } else {
                                $.dialog({
                                    lock: true,
                                    background: "#808080",
                                    opacity: 0.87,
                                    content: data,
                                    cancel: function () { }
                                });
                            }
                        });
                    } else {
                        $.dialog({
                            lock: true,
                            background: "#808080",
                            opacity: 0.87,
                            content: '<center>必须从下拉提示中选择楼盘！</center>',
                            cancel: function () { }
                        });
                    }
                });

            }
        });
    });

    //批量合并栋座
    $("#btnMerge").unbind("click");
    $("#btnMerge").bind("click", function () {
        var objModel = other.checkCount(true, "#ajaxPages input[class=btnValues]:checked", "请选择要合并信息！", "选择信息必须唯一！");
        if (objModel == false) {
            return false;
        }

        var tempKeyIds = "";
        $("#ajaxPages input[class=btnValues]:checked").each(function () {
            tempKeyIds += $(this).attr("keyid") + ",";
        });
        tempKeyIds = tempKeyIds.substring(0, tempKeyIds.length - 1);
        //合并栋座弹框
        $.dialog({
            id: "dialogMergeBuild",
            title: "合并栋座",
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: '<span id="spanMergeBuild">' + $("#divMergeBuild").html() + '</span>',
            init: function () {
                var tempDistrict = $("#spanMergeBuild [districts=Districts]"), tempMergeEstateName = $("#spanMergeBuild input[merge-buid=txtMergeEstateName]"), tempEstateName = "请输入楼盘名", tempTargetEstateKeyId = $("#spanMergeBuild input[name=TargetEstateKeyId]"), tempBtnSubmit = $("#spanMergeBuild input[btn-submit=1]");

                var tempAddMergeData = function () {
                    var tempMregeData = '';
                    for (var i = 0; i < objModel.length; i++) {
                        tempMregeData += ' <tr><td>' + $(objModel[i]).attr("build-name") + '</td><td>=>></td><td> <select style="border:1px solid #eaeaea;vertical-align:-1px;" goal-data="1" current-build="1" my-keyid="' + $(objModel[i]).attr("keyid") + '"><option selected value="-1">请选择</option></select></td></tr>';
                    }
                    $("#spanMergeBuild [add-MergeData=1]").html(tempMregeData);
                };
                tempAddMergeData();

                tempDistrict.change(function () {
                    tempMergeEstateName.val(tempEstateName);
                    tempTargetEstateKeyId.val("");
                    tempAddMergeData();
                    $("#spanMergeBuild input[btn-submit=1]").removeClass("btn-red").addClass("btn-gray");
                });

                tempMergeEstateName.focus(function () {
                    var $TempCurrentEleTxt = $(this);
                    if (tempDistrict.val() == "-1") {
                        $TempCurrentEleTxt.after(agencyVerify.greatErrorHtml($TempCurrentEleTxt, "请先选择行政区"));
                    }
                    if ($(this).val() == tempEstateName) {
                        $(this).val("");
                    }
                }).blur(function () {
                    $(this).next("span[class=wrong]").remove();
                    if (!other.trim($(this).val())) {
                        $(this).val(tempEstateName);
                        tempTargetEstateKeyId.val("");
                    }
                });

                $(tempMergeEstateName).autocomplete(function () {
                    if (tempDistrict.val() == "-1") {
                        return "";
                    } else {
                        return "/estate/AutoEstate?DistrictKeyId=" + tempDistrict.val() + "&EstateName=" + escape(tempMergeEstateName.val());
                    }

                }, {
                    width: 260,
                    max: 12,
                    selectFirst: false,
                    cacheLength: 0,
                    formatItem: function (row) {
                        if (row.EstateFullName != null && row.EstateFullName != "") {
                            return row.EstateFullName;
                        } else {
                            return row.EstateFullName;
                        }
                    },
                    formatResult: function (row) {
                        return row.EstateName;
                    }
                }).result(function (a, b) {
                    $(tempTargetEstateKeyId).val(b.KeyId);

                    $.AjaxAgency("/estate/find-building-select-by-estate", { "KeyId": b.KeyId }, function (respData) {
                        if (typeof respData == "object") {
                            var tempList = '<option selected value="-1">请选择</option>';
                            for (var i = 0; i < respData.length; i++) {
                                tempList += '<option value="' + respData[i].KeyId + '">' + respData[i].Value + '</option>';
                            }
                            //$("#spanMergeBuild [current-build=1]").html(tempList);
                            var tempCurrentBuidOption = $("#spanMergeBuild [current-build=1]");
                            tempCurrentBuidOption.html(tempList);
                            //option中过滤掉自己$("#select_id option[value='3']").remove()
                            for (var j = 0; j < tempCurrentBuidOption.length ; j++) {
                                $(tempCurrentBuidOption[j]).find("option[value=" + $(tempCurrentBuidOption[j]).attr("my-keyid") + "]").remove();
                            }
                            $("#spanMergeBuild [current-build=1]").unbind("change");
                            $("#spanMergeBuild [current-build=1]").change(function () {
                                if (pageNewEstateDetail.checkTargetKeyIds()) {
                                    $("#spanMergeBuild input[btn-submit=1]").removeClass("btn-gray").addClass("btn-red");
                                } else {
                                    $("#spanMergeBuild input[btn-submit=1]").removeClass("btn-red").addClass("btn-gray");
                                }
                            });
                        } else {
                            $.dialog({
                                lock: true,
                                background: "#808080",
                                opacity: 0.87,
                                content: '<center>' + respData + '</center>',
                                cancel: function () { }
                            });

                        }
                    });

                });

                tempMergeEstateName.change(function () {
                    tempTargetEstateKeyId.val("");
                    tempAddMergeData();
                    $("#spanMergeBuild input[btn-submit=1]").removeClass("btn-red").addClass("btn-gray");
                });

                pageNewEstateDetail.checkTargetKeyIds = function () {
                    var tempCheckMergeBuild = true;
                    $("#spanMergeBuild [current-build=1]").each(function () {
                        if ($(this).val() == "-1") {
                            tempCheckMergeBuild = false;
                            return false;
                        }
                    });
                    return tempCheckMergeBuild;
                };

                tempBtnSubmit.click(function () {
                    if (tempBtnSubmit.hasClass("btn-red")) {
                        var tempTargetKeyIds = '';
                        $("#spanMergeBuild [current-build=1]").each(function () {
                            tempTargetKeyIds += $(this).val() + ",";
                        });
                        tempTargetKeyIds = tempTargetKeyIds.substring(0, tempTargetKeyIds.length - 1);
                        var reqData = {
                            "OriginKeyIds": tempKeyIds,
                            "OriginEstateKeyId": $("#spanMergeBuild input[name=OriginEstateKeyId]").val(),
                            "TargetEstateKeyId": tempTargetEstateKeyId.val(),
                            "TargetKeyIds": tempTargetKeyIds
                        };
                        other.buttonDisable(tempBtnSubmit);
                        $.AjaxAgency("/estate/batch-merge-building", reqData, function (data) {
                            if (data == "ok") {
                                $.OKDialogAgency('<center>栋座合并成功！</center>', '提示', function () {
                                    window.location.href = window.location.href.split("#")[0];
                                }, function () {
                                    window.location.href = window.location.href.split("#")[0];
                                });

                                art.dialog.get('dialogMergeBuild').close();

                            } else {
                                $.dialog({
                                    lock: true,
                                    background: "#808080",
                                    opacity: 0.87,
                                    content: '<center>' + data + '</center>',
                                    cancel: function () { }
                                });
                            }
                            other.buttonStart(tempBtnSubmit);
                        });
                    } else {
                        $.dialog({
                            lock: true,
                            background: "#808080",
                            opacity: 0.87,
                            content: '<center>必须从下拉提示中选择楼盘或合并到的栋座目标未填！</center>',
                            cancel: function () { }
                        });
                    }

                });

            }
        });
    });
};

pageNewEstateDetail.findBuildingForEditInit = function () {

    dataBind.bindOption(3, "#selPropertyUsage");
    dataBind.bindOption(4, "#selBuildingType");
    $("#selBuildingTypeCode").val($("#selBuildingTypeCode").attr("bindvalue"));
    $("#selStairType").val($("#selStairType").attr("bindvalue"));
};

pageNewEstateDetail.success = function (data) {
    if (data == "ok") {
        $.dialog({
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: '<center>编辑成功！</center>'
        });
        art.dialog.get('dialogEditBuildingInfo').close();
        //window.location.href = window.location.href.split("#")[0];

    } else {
        $.dialog({
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: '<center>' + data + '</center>'
        });
    }

};

//插入房间列表
pageNewEstateDetail.insertRoomList = function () {
    $("#gdList .btnRoomList").unbind("click");
    $("#gdList .btnRoomList").bind("click", function () {
        var currentElement = $(this);
        var keyId = currentElement.attr("keyid");
        var isOpenCurrent = $(this).attr("room-open");
        if (isOpenCurrent == "true") {
            $(this).attr("room-open", "false");
            pageNewEstateDetail.EstateRoom.destoryx();
            currentElement.parent().parent().next().remove();
            return false;
        }
        //找到插入的房间表格进行删除，房间表格不唯一会导致js混乱
        $("#gdList .btnRoomList").each(function () {
            if ($(this).attr("room-open") == "true") {
                $(this).attr("room-open", "false");
                $(this).parent().parent().next().remove();
            }

        });

        var reqData = {
            "ColumnCount": 17,
            "BuildingKeyId": keyId,
            "BuildingTypeCode": currentElement.attr("building-type-code"),
            "RoomNoRuleItemValue": currentElement.attr("roomNoRuleItemValue"),
            "FirstFloor": currentElement.attr("first-floor")
        };
        $.AjaxAgency("/estate/find-house-paged-by-condition", reqData, function (data) {
            if (data.indexOf("#error:") > -1) {
                $.OKDialogAgency('<center>加载失败，请重新加载！</center>');
            } else {
                if (currentElement.attr("room-open") != "true") {
                    currentElement.parent().parent().after(data);
                    currentElement.attr("room-open", "true");
                    $("#hidOriginBuildingKeyId").val(keyId);
                }
            }

        });

    });
};

//房间号判重验证
pageNewEstateDetail.checkHouseNo = function (e) {
    var houseNo = "";
    var buildingKeyId = e.data.BuildingKeyId;
    var keyId = e.data.KeyId;

    if (!buildingKeyId) {
        return false;
    }

    if (e.data.IsAdd) {
        if ($("#spanAddHouseModel").find("#txtHouseNo").next(".wrong").length > 0) {
            return false;
        }
        houseNo = $("#spanAddHouseModel").find("#txtHouseNo").val();
    } else {
        if ($("#editRoomForm").find("#txtHouseNo").next(".wrong").length > 0) {
            return false;
        }
        houseNo = $("#editRoomForm").find("#txtHouseNo").val();
    }

    var reqData = {
        "HouseNo": houseNo,
        "BuildingKeyId": buildingKeyId,
        "KeyId": keyId
    };



    //$.AjaxAgency("/estate/check-house-name", reqData, function (data) {
    //if (data == "ok") {
    //} else if (data == "no") {
    //    if (e.data.IsAdd) {
    //        if ($("#spanAddHouseModel").find("#txtHouseNo").next(".wrong").length <= 0) {
    //            var $TempCurrentEleTxt = $("#spanAddHouseModel").find("#txtHouseNo");
    //            $TempCurrentEleTxt.addClass("checkError").after(agencyVerify.greatErrorHtml($TempCurrentEleTxt, "含有相同房号的房间"));
    //        }
    //    } else {
    //        if ($("#editRoomForm").find("#txtHouseNo").next(".wrong").length <= 0) {
    //            var $TempCurrentEleTxt = $("#editRoomForm").find("#txtHouseNo");
    //            $TempCurrentEleTxt.addClass("checkError").after(agencyVerify.greatErrorHtml($TempCurrentEleTxt, "含有相同房号的房间"));
    //        }
    //    }

    //} else {
    //    $.dialog({
    //        lock: true,
    //        background: "#808080",
    //        opacity: 0.87,
    //        content: '<div class="tc">' + data + '</div>',
    //        cancel: function () { }
    //    });
    //}
    //});



    $.ajax({
        type: "GET",
        url: "/estate/check-house-name",
        data: reqData,
        dataType: "json",
        success: function (data) {
            if (data == "ok") {
            } else if (data == "no") {
                if (e.data.IsAdd) {
                    if ($("#spanAddHouseModel").find("#txtHouseNo").next(".wrong").length <= 0) {
                        var $TempCurrentEleTxt = $("#spanAddHouseModel").find("#txtHouseNo");
                        $TempCurrentEleTxt.addClass("checkError").after(agencyVerify.greatErrorHtml($TempCurrentEleTxt, "含有相同房号的房间"));
                    }
                } else {
                    if ($("#editRoomForm").find("#txtHouseNo").next(".wrong").length <= 0) {
                        var $TempCurrentEleTxt = $("#editRoomForm").find("#txtHouseNo");
                        $TempCurrentEleTxt.addClass("checkError").after(agencyVerify.greatErrorHtml($TempCurrentEleTxt, "含有相同房号的房间"));
                    }
                }

            } else {
                $.dialog({
                    lock: true,
                    background: "#808080",
                    opacity: 0.87,
                    content: '<center>' + data + '</center>',
                    cancel: function () { }
                });
            }
        }
    });



};

//获取新增房间Model
pageNewEstateDetail.getAddHouseModel = function () {
    $("#btnAddHouse").unbind("click");
    $("#btnAddHouse").bind("click", function () {
        var buildingTypeCode = $(this).attr("building-type-code");
        var buildingKeyid = $(this).attr("building-keyid");
        var roomNoRuleItemValue = $(this).attr("roomNoRuleItemValue");
        var firstFloor = $(this).attr("first-floor");
        if (buildingTypeCode != "40") {
            $.dialog({
                id: "dialogAddHouse",
                title: "新增房间",
                lock: true,
                background: "#808080",
                opacity: 0.87,
                width: 750,
                init: function () {
                    //表单验证
                    $("#spanAddHouseModel").find("#txtHouseNo").bind("blur", function () {
                        $(this).removeClass("checkError").next(".wrong").remove();
                    });
                    agencyVerify.notNullInput(null, "#spanAddHouseModel input[notnull=1],select[notnull=1]", false, "blur");
                    agencyVerify.nonnegativeIntInput("#spanAddHouseModel input[isint=1]", true);
                    agencyVerify.nonnegativeInput("#spanAddHouseModel input[isfloat=1]", true);
                    agencyVerify.zhengFuIntInput("#spanAddHouseModel input[iszhengfu=1]", true);
                    $("#spanAddHouseModel input[start-floor=1]").focus(function () {
                        $(this).removeClass("checkError").next("span[class=wrong]").remove();
                    }).blur(function () {
                        if ($(this).next(".wrong").length <= 0 && firstFloor.length > 0 && parseInt($(this).val()) < parseInt(firstFloor)) {
                            var $TempCurrentEleTxt = $(this);
                            $TempCurrentEleTxt.addClass("checkError").after(agencyVerify.greatErrorHtml($TempCurrentEleTxt, "楼层不能小于" + firstFloor + "！"));
                        }
                    });

                    other.numberBigOrSmall("#spanAddHouseModel [name=FloorFrom]", "#spanAddHouseModel [name=FloorTo]");
                    //判断弹框模板的显示方式
                    if (buildingTypeCode == "10") {
                        //房号规则验证
                        agencyVerify.regexCheck(null, "#spanAddHouseModel #txtHouseNo", eval("/" + roomNoRuleItemValue + "/"), "房号不正确", false, "blur", function () {
                            if ($("#spanAddHouseModel :checkbox[name=IsSpecialHouseNo]").get(0).checked) {
                                return false;
                            } else {
                                return true;
                            }
                        });
                        var $TempIsSpecialHouseNo = $($("#spanAddHouseModel :checkbox[name=IsSpecialHouseNo]").get(0));
                        $TempIsSpecialHouseNo.unbind("click");
                        $TempIsSpecialHouseNo.bind("click", function () {
                            $("#spanAddHouseModel #txtHouseNo").blur();
                        });
                    } else {
                        $("#spanAddHouseModel").find(":checkbox[name=IsSpecialHouseNo]").parent("label").remove();

                    }

                    $("#spanAddHouseModel").find("#txtHouseNo").bind("blur", { "IsAdd": true, "BuildingKeyId": buildingKeyid }, pageNewEstateDetail.checkHouseNo);
                },
                content: '<span id="spanAddHouseModel" building-keyid="' + buildingKeyid + '" building-type-code="' + buildingTypeCode + '">' + $("#divAddHouseModel").html() + '</span>'
            });

            //注册模版切换事件
            $("#spanAddHouseModel").find("label.lblSingleAddHouseModel,label.lblBatchAddHouseModel").click(function () {
                $("#spanAddHouseModel").find(".wrong").each(function () {
                    $(this).prev(".checkError").removeClass("checkError");
                    $(this).remove();
                });
                if ($(this).attr("class") == "lblSingleAddHouseModel") {
                    $(".divSingleAddHouseModel").show();
                    $(".divBatchAddHouseModel").hide();
                } else {
                    $(".divBatchAddHouseModel").show();
                    $(".divSingleAddHouseModel").hide();
                }
            });
            $("#spanAddHouseModel").find("label").eq(0).click();
        } else {
            $.dialog({
                id: "dialogAddHouse",
                title: "新增车位",
                lock: true,
                background: "#808080",
                opacity: 0.87,
                init: function () {
                    //表单验证
                    agencyVerify.notNullInput(null, "#spanAddHouseModel input[notnull=1],select[notnull=1]", false, "blur");
                },
                content: '<span id="spanAddHouseModel" building-keyid="' + buildingKeyid + '" building-type-code="' + buildingTypeCode + '">' + $("#divAddCarModel").html() + '</span>'
            });

        }

    });
};

//新增单个房间
pageNewEstateDetail.addSingleHouse = function (carModel) {
    $("#spanAddHouseModel .divSingleAddHouseModel input[notnull=1],select[notnull=1]").each(function () {
        $(this).blur();
    });
    if ($("#spanAddHouseModel").find(".wrong").length > 0) {
        return;
    }
    var reqData;
    if (carModel) {
        $(carModel + " input[notnull=1],select[notnull=1]").each(function () {
            $(this).blur();
        });
        if ($(carModel).find(".wrong").length > 0) {
            return;
        }

        reqData = other.getSubmitData(carModel);
    } else {
        reqData = other.getSubmitData("#spanAddHouseModel .divSingleAddHouseModel");
    }

    if (!reqData) {
        return false;
    }
    reqData["BuildingTypeCode"] = $("#spanAddHouseModel").attr("building-type-code");
    reqData["BuildingKeyId"] = $("#spanAddHouseModel").attr("building-keyid");
    reqData["HouseRightName"] = "";
    var houseRightName = $("input[name='HouseRightName']");
    houseRightName.each(function () {
        reqData["HouseRightName"] += $(this).val() + ",";
    });
    $.AjaxAgency("/estate/create-house", reqData, function (data) {
        if (data == "ok") {
            art.dialog.get('dialogAddHouse').close();
            $.dialog({
                lock: true,
                background: "#808080",
                opacity: 0.87,
                cancel: false,
                ok: function () {
                    window.location.href = window.location.href.split('#')[0];
                },
                content: '<center> 新增成功！</center>'

            });

        } else {
            $.dialog({
                lock: true,
                background: "#808080",
                opacity: 0.87,
                content: '<center>' + data + '</center>',
                cancel: function () { }
            });
        }

    });
};

//批量新增房间中楼层切换
pageNewEstateDetail.foolrChange = function (ele) {
    if ($(ele).val() == "1") {
        $("#dlAllFoolr").css("display", "");
        $("#divOddEvenFoolr").css("display", "none");
    } else if ($(ele).val() == "2") {
        $("#divOddEvenFoolr").css("display", "");
        $("#dlAllFoolr").css("display", "none");
    }
};

//批量新增房间
pageNewEstateDetail.addBatchHouse = function () {
    $("#spanAddHouseModel .divBatchAddHouseModel input[notnull=1],select[notnull=1]").each(function () {
        $(this).blur();
    });
    if ($("#spanAddHouseModel").find(".wrong").length > 0) {
        return;
    }

    var reqData = other.getSubmitData("#spanAddHouseModel .divBatchAddHouseModel");
    if (!reqData) {
        return;
    }

    reqData["BuildingTypeCode"] = $("#spanAddHouseModel").attr("building-type-code");
    reqData["BuildingKeyId"] = $("#spanAddHouseModel").attr("building-keyid");
    $.AjaxAgency("/estate/batch-create-house", reqData, function (data) {
        if (data == "ok") {
            $.dialog({
                lock: true,
                background: "#808080",
                opacity: 0.87,
                cancel: false,
                ok: function () {
                    window.location.href = window.location.href.split("#")[0];
                },
                content: '<center> 批量新增成功！</center>'

            });
            art.dialog.get('dialogAddHouse').close();

        } else {
            $.dialog({
                lock: true,
                background: "#808080",
                opacity: 0.87,
                content: '<center>' + data + '</center>',
                cancel: function () { }
            });
        }
    });
};

//房间页面初始化
pageNewEstateDetail.RoomPageInit = function () {
    //工具栏按钮状态处理
    var $btnRoomList = $("tr.follow-status").prev().find(".btnRoomList").eq(0);
    if ($btnRoomList.attr("is-ban-add") == "1") {
        if ($("#hidHouseNoLockPermisstion").val() == "0") {
            $("#btnAddHouse").unbind("click");
            $("#btnAddHouse").addClass("disabled").bind("click", function () {
                return false;
            });
        }
        if ($("#hidHouseNoLockPermisstion").val() == "1") {
            pageNewEstateDetail.getAddHouseModel();
        }
    } else {
        pageNewEstateDetail.getAddHouseModel();
    }
    if ($btnRoomList.attr("is-ban-delete") == "1") {
        $("#btnDelHouse").unbind("click");
        $("#btnDelHouse").addClass("disabled").bind("click", function () {
            return false;
        });
        //全选
        $("#chbSelectAllRoom").unbind("click", pageNewEstateDetail.btnDelHouseChange);

    } else {
        $("tr.follow-status input[class=roomCheckBox]").bind("click", function () {
            pageNewEstateDetail.btnDelHouseChange();
        });
        //全选
        other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", pageNewEstateDetail.btnDelHouseChange, true);

        //注册删除房间事件
        pageNewEstateDetail.delHouse();
    }
    //注册转移房间按钮
    pageNewEstateDetail.transferHouse();
    //注册 锁定房间按钮
    pageNewEstateDetail.unLockHouse();
    pageNewEstateDetail.lockHouse();
    //注册批量设置一手房
    pageNewEstateDetail.BatchSetFirstHand();
    //注册合并房间按钮
    pageNewEstateDetail.mergeHouse();

    //房间搜索智能提示
    pageNewEstateDetail.searchHouseAutoMatch($btnRoomList.attr("keyid"));

    $("#gdRoomList input[class=roomCheckBox]").change(function () {
        pageNewEstateDetail.btnTransferMergeChange();
    });

    other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", pageNewEstateDetail.btnTransferMergeChange, true);
    $("#gdRoomList input[class=roomCheckBox]").change(function () {
        pageNewEstateDetail.btnLockHouseChange();
    });

    other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", pageNewEstateDetail.btnLockHouseChange, true);

    $("#gdRoomList input[class=roomCheckBox]").change(function () {

        pageNewEstateDetail.btnSetFirstHandChange();
    });
    other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", pageNewEstateDetail.btnSetFirstHandChange, true);
    //房间搜索
    pageNewEstateDetail.searchHouse();


    //给编辑按钮赋值是否禁止修改
    $("#gdRoomList .edit-house").each(function () {
        $(this).attr("is-ban-update", $btnRoomList.attr("is-ban-update"));
    });
};

//房间按钮样式变化
pageNewEstateDetail.btnDelHouseChange = function () {
    var checkedCount = 0;
    $("#gdRoomList input[class=roomCheckBox]").each(function () {
        if ($(this).attr("checked") == "checked") {
            checkedCount = checkedCount + 1;
        }
    });
    if (checkedCount == 1) {
        $("#btnDelHouse").removeClass("disabled");
    } else if (checkedCount == 2) {

    } else {
        $("#btnDelHouse").addClass("disabled");
    }

    if (checkedCount > 1) {
        $("#btnDelHouse").removeClass("disabled");
    }

    if (checkedCount < 1) {
        $("#btnDelHouse").addClass("disabled");
    }
};

//重置房间的按钮样式
pageNewEstateDetail.resetRoomBtnChange = function () {
    $("#btnMergeHouse,#btnTransferHouse,#btnDelHouse").addClass("disabled");

};
pageNewEstateDetail.btnLockHouseChange = function () {
    var checkedCount = 0;
    $("#gdRoomList input[class=roomCheckBox]").each(function () {
        if ($(this).attr("checked") == "checked") {
            checkedCount = checkedCount + 1;
        }
    });

    if (checkedCount == 1) {
        $("#btnLockHouse,#btnUnLockHouse").removeClass("disabled");
    }

    if (checkedCount > 1) {
        $("#btnLockHouse,#btnUnLockHouse").removeClass("disabled");
    }

    if (checkedCount < 1) {
        $("#btnLockHouse,#btnUnLockHouse").addClass("disabled");
    }
};
pageNewEstateDetail.btnSetFirstHandChange = function () {

    var checkedCount = 0;
    $("#gdRoomList input[class=roomCheckBox]").each(function () {
        if ($(this).attr("checked") == "checked") {
            checkedCount = checkedCount + 1;
        }
    });

    if (checkedCount == 1) {
        $("#btnFirstHand").removeClass("disabled");
    }

    if (checkedCount > 1) {
        $("#btnFirstHand").removeClass("disabled");
    }

    if (checkedCount < 1) {
        $("#btnFirstHand").addClass("disabled");
    }
};
//房间转移合并按钮样式变化
pageNewEstateDetail.btnTransferMergeChange = function () {
    var checkedCount = 0;
    $("#gdRoomList input[class=roomCheckBox]").each(function () {
        if ($(this).attr("checked") == "checked") {
            checkedCount = checkedCount + 1;
        }
    });

    if (checkedCount == 1) {
        $("#btnTransferHouse").removeClass("disabled");
        $("#btnMergeHouse").addClass("disabled");
    } else if (checkedCount == 2) {
        $("#btnMergeHouse").removeClass("disabled");
    } else {
        $("#btnTransferHouse,#btnMergeHouse").addClass("disabled");
    }

    if (checkedCount > 1) {
        $("#btnTransferHouse").removeClass("disabled");
    }

    if (checkedCount < 1) {
        $("#btnTransferHouse,#btnMergeHouse").addClass("disabled");
    }
};

//房间搜索智能提示
pageNewEstateDetail.searchHouseAutoMatch = function (buildingKeyId) {
    //房间搜索智能提示Url
    pageNewEstateDetail.getHouseUrl = function () {
        return "/Estate/auto-match-house-no?BuildingKeyId=" + buildingKeyId + "&HouseNo=" + escape($("#txtHouseNo").val());
    };
    //楼盘自动完成及赋值隐藏域
    $("#txtHouseNo").autocomplete(pageNewEstateDetail.getHouseUrl, {
        width: 260,
        max: 1000,
        Default: 1,
        selectFirst: false,
        cacheLength: 0,
        formatItem: function (row) {
            return row.ItemText;
        },
        formatResult: function (row) {
            return row.ItemText;
        }
    });
};

//搜索房间
pageNewEstateDetail.searchHouse = function () {

    $("#btnSearchHouse").unbind("click");
    $("#btnSearchHouse").bind("click", function () {
        pageNewEstateDetail.resetRoomBtnChange();
        var $btnRoomList = $("tr.follow-status").prev().find(".btnRoomList").eq(0);
        var reqData = {
            "BuildingKeyId": $btnRoomList.attr("keyid"),
            "BuildingTypeCode": $btnRoomList.attr("building-type-code"),
            "RoomNoRuleItemValue": $btnRoomList.attr("roomNoRuleItemValue"),
            "HouseNo": $("#txtHouseNo").val(),
            "IsSearch": true
        };
        $.AjaxAgency("/estate/find-house-paged-by-condition", reqData, function (data) {
            if (data.indexOf("#error:") > -1) {
                $.dialog({
                    lock: true,
                    background: "#808080",
                    opacity: 0.87,
                    content: '<center>加载失败，请重新加载！</center>',
                    cancel: function () { }
                });
            } else {
                $(data).replaceAll("#gdRoomList");
                //重新绑定丢失事件
                other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", function () {
                    if ($btnRoomList.attr("is-ban-delete") == "0") {
                        pageNewEstateDetail.btnDelHouseChange();
                   
                    }

                });
                //重置房间删除按钮样式
                if ($btnRoomList.attr("is-ban-delete") == "0") {
                    $("#gdRoomList input[class=roomCheckBox]").change(function () {
                        pageNewEstateDetail.btnDelHouseChange();
                    });
                }
                $("#gdRoomList input[class=roomCheckBox]").change(function () {
                    pageNewEstateDetail.btnTransferMergeChange();
                    //pageNewEstateDetail.lockHouse();
                    //pageNewEstateDetail.unLockHouse();
                    //pageNewEstateDetail.BatchSetFirstHand();
                });
                other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", pageNewEstateDetail.btnTransferMergeChange, true);

                //锁定/解锁房源
                $("#gdRoomList input[class=roomCheckBox]").change(function () {
                    pageNewEstateDetail.btnLockHouseChange();
                });

                other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", pageNewEstateDetail.btnLockHouseChange, true);

                //一手

                $("#gdRoomList input[class=roomCheckBox]").change(function () {

                    pageNewEstateDetail.btnSetFirstHandChange();
                });
                other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", pageNewEstateDetail.btnSetFirstHandChange, true);
            }
        });
    });
};


pageNewEstateDetail.PrevPage = function (page) {
    $("#btnPrev").unbind("click");
    $("#btnPrev").bind("click", function () {
        pageNewEstateDetail.resetRoomBtnChange();
        var $btnRoomList = $("tr.follow-status").prev().find(".btnRoomList").eq(0);
        var pageIndex = page - 1;

        var reqData = {
            "BuildingKeyId": $btnRoomList.attr("keyid"),
            "BuildingTypeCode": $btnRoomList.attr("building-type-code"),
            "RoomNoRuleItemValue": $btnRoomList.attr("roomNoRuleItemValue"),
            "HouseNo": $("#txtHouseNo").val(),
            "IsSearch": true
        };
        $.AjaxAgency("/estate/find-house-paged-by-condition?pageindex=" + pageIndex, reqData, function (data) {
            if (data.indexOf("#error:") > -1) {
                $.dialog({
                    lock: true,
                    background: "#808080",
                    opacity: 0.87,
                    content: '<center>加载失败，请重新加载！</center>',
                    cancel: function () { }
                });
            } else {
                $(data).replaceAll("#gdRoomList");
                //重新绑定丢失事件
                other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", function () {
                    if ($btnRoomList.attr("is-ban-delete") == "0") {
                        pageNewEstateDetail.btnDelHouseChange();
                    }

                });
                //重置房间删除按钮样式
                if ($btnRoomList.attr("is-ban-delete") == "0") {
                    $("#gdRoomList input[class=roomCheckBox]").change(function () {
                        pageNewEstateDetail.btnDelHouseChange();
                    });
                }
                $("#gdRoomList input[class=roomCheckBox]").change(function () {
                    pageNewEstateDetail.btnTransferMergeChange();
                });
                other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", pageNewEstateDetail.btnTransferMergeChange, true);


                //锁定/解锁房源
                $("#gdRoomList input[class=roomCheckBox]").change(function () {
                    pageNewEstateDetail.btnLockHouseChange();
                });

                other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", pageNewEstateDetail.btnLockHouseChange, true);

                //一手

                $("#gdRoomList input[class=roomCheckBox]").change(function () {

                    pageNewEstateDetail.btnSetFirstHandChange();
                });
                other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", pageNewEstateDetail.btnSetFirstHandChange, true);
            }
        });
    });
};

pageNewEstateDetail.NextPage = function (page) {

    $("#btnNext").unbind("click");
    $("#btnNext").bind("click", function () {
        pageNewEstateDetail.resetRoomBtnChange();
        var $btnRoomList = $("tr.follow-status").prev().find(".btnRoomList").eq(0);
        var pageIndex = page + 1;
        var reqData = {
            "BuildingKeyId": $btnRoomList.attr("keyid"),
            "BuildingTypeCode": $btnRoomList.attr("building-type-code"),
            "RoomNoRuleItemValue": $btnRoomList.attr("roomNoRuleItemValue"),
            "HouseNo": $("#txtHouseNo").val(),
            "IsSearch": true
        };
        $.AjaxAgency("/estate/find-house-paged-by-condition?pageindex=" + pageIndex, reqData, function (data) {
            if (data.indexOf("#error:") > -1) {
                $.dialog({
                    lock: true,
                    background: "#808080",
                    opacity: 0.87,
                    content: '<center>加载失败，请重新加载！</center>',
                    cancel: function () { }
                });
            } else {
                $(data).replaceAll("#gdRoomList");
                //重新绑定丢失事件
                other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", function () {
                    if ($btnRoomList.attr("is-ban-delete") == "0") {
                        pageNewEstateDetail.btnDelHouseChange();
                    }

                });
                //重置房间删除按钮样式
                if ($btnRoomList.attr("is-ban-delete") == "0") {
                    $("#gdRoomList input[class=roomCheckBox]").change(function () {
                        pageNewEstateDetail.btnDelHouseChange();
                    });
                }
                $("#gdRoomList input[class=roomCheckBox]").change(function () {
                    pageNewEstateDetail.btnTransferMergeChange();
                });
                other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", pageNewEstateDetail.btnTransferMergeChange, true);

                //锁定/解锁房源
                $("#gdRoomList input[class=roomCheckBox]").change(function () {
                    pageNewEstateDetail.btnLockHouseChange();
                });

                other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", pageNewEstateDetail.btnLockHouseChange, true);

                //一手

                $("#gdRoomList input[class=roomCheckBox]").change(function () {

                    pageNewEstateDetail.btnSetFirstHandChange();
                });
                other.selectAll("#chbSelectAllRoom", "#gdRoomList .roomCheckBox", pageNewEstateDetail.btnSetFirstHandChange, true);
            }
        });
    });
};
//批量锁定房间
pageNewEstateDetail.lockHouse = function () {
    $("#btnLockHouse").unbind("click");
    $("#btnLockHouse").bind("click", function () {
        var objModel = other.checkCount(true, "#gdRoomList input[class=roomCheckBox]:checked", "请选择信息！", "选择信息必须唯一！");
        if (objModel == false) {
            return false;
        }
        var tempKeyIds = "";
        $("#gdRoomList input[class=roomCheckBox]:checked").each(function () {
            tempKeyIds += $(this).attr("keyid") + ",";
        });
        tempKeyIds = tempKeyIds.substring(0, tempKeyIds.length - 1);
        //删除弹框
        $.dialog({
            id: "dialogLockHouse",
            title: "锁定房间",
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: '<center>您确定要锁定选中的房间吗？</center>',
            ok: function () {
                var reqData = {
                    "keyid": tempKeyIds
                };
                $.AjaxAgency("/estate/batch-set-house-lock", reqData, function (data) {
                    if (data == "ok") {
                        $.dialog({
                            lock: true,
                            background: "#808080",
                            opacity: 0.87,
                            content: '<center>锁定成功！</center>'
                        }).time(1000);

                        art.dialog.get("dialogLockHouse").close();
                        window.location.href = window.location.href.split("#")[0];
                    } else {
                        $.dialog({
                            lock: true,
                            background: "#808080",
                            opacity: 0.87,
                            content: data
                        });
                        art.dialog.get("dialogLockHouse").close();
                    }
                });
                return false;
            },
            cancel: true
        });
    });
};
//批量设置一手房
pageNewEstateDetail.BatchSetFirstHand = function () {
    $("#btnFirstHand").unbind("click");
    $("#btnFirstHand").bind("click", function () {
        var objModel = other.checkCount(true, "#gdRoomList input[class=roomCheckBox]:checked", "请选择信息！", "选择信息必须唯一！");
        if (objModel == false) {
            return false;
        }
        var tempKeyIds = "";
        $("#gdRoomList input[class=roomCheckBox]:checked").each(function () {
            tempKeyIds += $(this).attr("keyid") + ",";
        });
        tempKeyIds = tempKeyIds.substring(0, tempKeyIds.length - 1);
        //一手房设置弹框
        $.dialog({
            id: "dialogFirstHand",
            title: "设置一手房源",
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: '<center>您确定要将选中的房间设置为一手房源吗？</center>',
            ok: function () {
                var reqData = {
                    "keyid": tempKeyIds
                };
                $.AjaxAgency("/estate/batch-set-First-Hand", reqData, function (data) {
                    if (data == "ok") {
                        $.dialog({
                            lock: true,
                            background: "#808080",
                            opacity: 0.87,
                            content: '<center>设置成功！</center>'
                        }).time(1000);

                        art.dialog.get("dialogFirstHand").close();
                        window.location.href = window.location.href.split("#")[0];
                    } else {
                        $.dialog({
                            lock: true,
                            background: "#808080",
                            opacity: 0.87,
                            content: data
                        });
                        art.dialog.get("dialogFirstHand").close();
                    }
                });
                return false;
            },
            cancel: true
        });
    });
};
//批量删除房间
pageNewEstateDetail.delHouse = function () {
    $("#btnDelHouse").unbind("click");
    $("#btnDelHouse").bind("click", function () {
        var objModel = other.checkCount(true, "#gdRoomList input[class=roomCheckBox]:checked", "请选择信息！", "选择信息必须唯一！");
        if (objModel == false) {
            return false;
        }
        var tempKeyIds = "";
        $("#gdRoomList input[class=roomCheckBox]:checked").each(function () {
            tempKeyIds += $(this).attr("keyid") + ",";
        });
        tempKeyIds = tempKeyIds.substring(0, tempKeyIds.length - 1);
        //删除弹框
        $.dialog({
            id: "dialogDelHouse",
            title: "删除房间",
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: '<center>您确定要删除选中的信息吗？</center>',
            ok: function () {
                var reqData = {
                    "keyid": tempKeyIds
                };
                $.AjaxAgency("/estate/batch-remove-house", reqData, function (data) {
                    if (data == "ok") {
                        $.dialog({
                            lock: true,
                            background: "#808080",
                            opacity: 0.87,
                            content: '<center>删除成功！</center>'
                        }).time(1000);

                        art.dialog.get("dialogDelHouse").close();
                        window.location.href = window.location.href.split("#")[0];
                    } else {
                        $.dialog({
                            lock: true,
                            background: "#808080",
                            opacity: 0.87,
                            content: data
                        });
                        art.dialog.get("dialogDelHouse").close();
                    }
                });
                return false;
            },
            cancel: true
        });
    });
};
//批量解锁房间
pageNewEstateDetail.unLockHouse = function () {
    $("#btnUnLockHouse").unbind("click");
    $("#btnUnLockHouse").bind("click", function () {
        var objModel = other.checkCount(true, "#gdRoomList input[class=roomCheckBox]:checked", "请选择信息！", "选择信息必须唯一！");
        if (objModel == false) {
            return false;
        }
        var tempKeyIds = "";
        $("#gdRoomList input[class=roomCheckBox]:checked").each(function () {
            tempKeyIds += $(this).attr("keyid") + ",";
        });
        tempKeyIds = tempKeyIds.substring(0, tempKeyIds.length - 1);
        //删除弹框
        $.dialog({
            id: "dialogUnLockHouse",
            title: "解锁房间",
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: '<center>您确定要解锁选中的房间吗？</center>',
            ok: function () {
                var reqData = {
                    "keyid": tempKeyIds
                };
                $.AjaxAgency("/estate/batch-set-house-unlock", reqData, function (data) {
                    if (data == "ok") {
                        $.dialog({
                            lock: true,
                            background: "#808080",
                            opacity: 0.87,
                            content: '<center>解锁成功！</center>'
                        }).time(1000);

                        art.dialog.get("dialogUnLockHouse").close();
                        window.location.href = window.location.href.split("#")[0];
                    } else {
                        $.dialog({
                            lock: true,
                            background: "#808080",
                            opacity: 0.87,
                            content: data
                        });
                        art.dialog.get("dialogUnLockHouse").close();
                    }
                });
                return false;
            },
            cancel: true
        });
    });
};
//批量转移房间
pageNewEstateDetail.transferHouse = function () {
    $("#btnTransferHouse").unbind("click");
    $("#btnTransferHouse").bind("click", function () {
        var objModel = other.checkCount(true, "#gdRoomList input[class=roomCheckBox]:checked", "没有选择任何数据！", "");
        if (objModel == false) {
            return false;
        }
        var originBuildingKeyId = $(this).attr("building-keyid"), tempKeyIds = "";
        $("#gdRoomList input[class=roomCheckBox]:checked").each(function () {
            tempKeyIds += $(this).attr("keyid") + ",";
        });
        tempKeyIds = tempKeyIds.substring(0, tempKeyIds.length - 1);

        $.dialog({
            id: "dialogTransferHouse",
            title: "转移房间",
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: '<span id="spanTransferHouse">' + $("#divTransferHouse").html() + '</span>',
            init: function () {
                var tempDistrict = $("#spanTransferHouse [districts=Districts]"), tempMergeEstateName = $("#spanTransferHouse input[merge-buid=txtMergeEstateName]"), tempEstateName = "请输入楼盘名", tempTargetEstateKeyId = $("#spanTransferHouse input[name=TargetEstateKeyId]"), tempBtnSubmit = $("#spanTransferHouse input[btn-submit=1]");

                tempDistrict.change(function () {
                    tempMergeEstateName.val(tempEstateName);
                    tempTargetEstateKeyId.val("");
                    $("#spanTransferHouse [current-build=1]").html('<option selected value="-1">请选择栋座</option>');
                    $("#spanTransferHouse input[btn-submit=1]").removeClass("btn-red");
                });

                tempMergeEstateName.focus(function () {
                    if (tempDistrict.val() == "-1") {
                        var $TempCurrentEleTxt = $(this);
                        $(this).after(agencyVerify.greatErrorHtml($TempCurrentEleTxt, "请先选择行政区"));
                    }
                    if ($(this).val() == tempEstateName) {
                        $(this).val("");
                    }
                }).blur(function () {
                    $(this).next("span[class=wrong]").remove();
                    if (!other.trim($(this).val())) {
                        $(this).val(tempEstateName);
                        tempTargetEstateKeyId.val("");
                    }
                });

                $(tempMergeEstateName).autocomplete(function () {
                    if (tempDistrict.val() == "-1") {
                        return "";
                    } else {
                        return "/estate/AutoEstate?DistrictKeyId=" + tempDistrict.val() + "&EstateName=" + escape(tempMergeEstateName.val());
                    }

                }, {
                    width: 260,
                    max: 12,
                    selectFirst: false,
                    cacheLength: 0,
                    formatItem: function (row) {
                        if (row.EstateFullName != null && row.EstateFullName != "") {
                            return row.EstateFullName;
                        } else {
                            return row.EstateFullName;
                        }
                    },
                    formatResult: function (row) {
                        return row.EstateName;
                    }
                }).result(function (a, b) {
                    $(tempTargetEstateKeyId).val(b.KeyId);

                    $.AjaxAgency("/estate/find-building-select-by-estate", { "KeyId": b.KeyId }, function (respData) {
                        if (typeof respData == "object") {
                            var tempList = '<option selected value="-1">请选择栋座</option>';
                            for (var i = 0; i < respData.length; i++) {
                                tempList += '<option value="' + respData[i].KeyId + '">' + respData[i].Value + '</option>';
                            }

                            $("#spanTransferHouse [current-build=1]").html(tempList);
                            $("#spanTransferHouse [current-build=1]").unbind("change");
                            $("#spanTransferHouse [current-build=1]").change(function () {
                                if (pageNewEstateDetail.checkTargetKeyIds()) {
                                    $("#spanTransferHouse input[btn-submit=1]").removeClass("btn-gray").addClass("btn-red");
                                } else {
                                    $("#spanTransferHouse input[btn-submit=1]").removeClass("btn-red");
                                }
                            });
                        } else {
                            $.dialog({
                                lock: true,
                                background: "#808080",
                                opacity: 0.87,
                                content: '<div class="tc">' + respData + '</div>',
                                cancel: function () { }
                            });

                        }
                    });

                });

                tempMergeEstateName.change(function () {
                    tempTargetEstateKeyId.val("");
                    $("#spanTransferHouse [current-build=1]").html('<option selected value="-1">请选择栋座</option>');
                    $("#spanTransferHouse input[btn-submit=1]").removeClass("btn-red");
                });

                pageNewEstateDetail.checkTargetKeyIds = function () {
                    var tempCheckMergeBuild = true;
                    $("#spanTransferHouse [current-build=1]").each(function () {
                        if ($(this).val() == "-1") {
                            tempCheckMergeBuild = false;
                            return false;
                        }
                    });
                    return tempCheckMergeBuild;
                };

                tempBtnSubmit.click(function () {
                    if (tempBtnSubmit.hasClass("btn-red")) {
                        var tempTargetKeyIds = $("#spanTransferHouse [current-build=1]").val();

                        var reqData = {
                            "HouseKeyIds": tempKeyIds,
                            "OriginBuildingKeyId": originBuildingKeyId,
                            "TargetEstateKeyId": tempTargetEstateKeyId.val(),
                            "TargetBuildingKeyId": tempTargetKeyIds

                        };
                        other.buttonDisable(tempBtnSubmit);
                        $.AjaxAgency("/estate/batch-transfer-house", reqData, function (data) {
                            if (data == "ok") {
                                $.dialog({
                                    lock: true,
                                    background: "#808080",
                                    opacity: 0.87,
                                    content: '<center>转移成功！</center>',
                                    cancel: function () { }
                                });

                                art.dialog.get('dialogTransferHouse').close();
                                window.location.href = window.location.href.split("#")[0];
                            } else {
                                $.dialog({
                                    lock: true,
                                    background: "#808080",
                                    opacity: 0.87,
                                    content: '<center>' + data + '</center>',
                                    cancel: function () { }
                                });
                            }
                            other.buttonStart(tempBtnSubmit);
                        });
                    } else {
                        //alert("必须从下拉提示中选择楼盘！");
                    }

                });

            }
        });
    });
};

//批量合并房间
pageNewEstateDetail.mergeHouse = function () {
    $("#btnMergeHouse").unbind("click");
    $("#btnMergeHouse").bind("click", function () {
        var objModel = other.checkCount(true, "#gdRoomList input[class=roomCheckBox]:checked", "没有选择任何数据！", "", function () {
            if ($("#gdRoomList input[class=roomCheckBox]:checked").length == 2) {
                return true;
            } else {
                $.dialog({
                    lock: true,
                    background: "#808080",
                    opacity: 0.87,
                    content: '<center>数据有且只能选择两条！</center>',
                    cancel: function () { }
                });
                return false;
            }

        });
        if (objModel == false) {
            return false;
        }
        var originBuildingKeyId = $(this).attr("building-keyid"), tempKeyIds = "";
        $("#gdRoomList input[class=roomCheckBox]:checked").each(function () {
            tempKeyIds += $(this).attr("keyid") + ",";
        });
        tempKeyIds = tempKeyIds.substring(0, tempKeyIds.length - 1);
        var tempChiefOption = "";

        pageNewEstateDetail.tempChiefFunc = function name() {
            $.AjaxAgency("/estate/find-property-chief-by-houses", { "KeyIds": tempKeyIds }, function (chiefData) {
                if (typeof chiefData == "object") {
                    if (chiefData.length <= 0) {
                        $.dialog({
                            lock: true,
                            background: "#808080",
                            opacity: 0.87,
                            content: '<center>所选房间不存在归属人，不能合并！</center>',
                            cancel: function () { }
                        });

                        return;
                    } else if (chiefData.length < 2) {
                        var tempResult = "";
                        for (var j = 0; j < objModel.length; j++) {
                            if ($(objModel[j]).attr("keyid") != chiefData[0].HouseKeyId) {
                                tempResult = $(objModel[j]).attr("house-no");
                                break;
                            }
                        }

                        $.dialog({
                            lock: true,
                            background: "#808080",
                            opacity: 0.87,
                            content: '<center>所选房间:' + tempResult + '不存在归属人，不能合并！</center>',
                            cancel: function () { }
                        });
                        return;
                    }
                    else if (chiefData.length >= 2) {
                        var tempResult0 = $(objModel[0]).attr("house-no");
                        var tempResult1 = $(objModel[1]).attr("house-no");
                        var temNum0 = 0, temNum1 = 0;
                        var proNum0 = "", proNum1 = "";
                        for (var i = 0; i < chiefData.length; i++) {
                            var temHouseKeyId = chiefData[i].HouseKeyId;
                            var temProNum = chiefData[i].PropertyNo;
                            if ($(objModel[0]).attr("keyid") == temHouseKeyId) {
                                temNum0++;
                                proNum0 += proNum0.length > 0 ? "," + temProNum : temProNum;
                            }
                            if ($(objModel[1]).attr("keyid") == temHouseKeyId) {
                                temNum1++;
                                proNum1 += proNum1.length > 0 ? "," + temProNum : temProNum;
                            }
                        }
                        if (temNum0 > 1 || temNum1 > 1) {
                            var houseTxt = "";
                            if (temNum0 > 1) {
                                houseTxt += tempResult0 + "[" + proNum0 + "]";
                            }
                            if (temNum1 > 1) {
                                houseTxt += houseTxt.length > 0 ? "," + tempResult1 : tempResult1;
                                houseTxt += "[" + proNum1 + "]";
                            }
                            $.dialog({
                                lock: true,
                                background: "#808080",
                                opacity: 0.87,
                                content: '<center>所选房间:' + houseTxt + '对应多个房源存！</center>',
                                cancel: function () { }
                            });
                            return;
                        } else {
                            if (proNum0.length > 0) $(objModel[0]).data("PropertyNo", proNum0);
                            if (proNum1.length > 0) $(objModel[1]).data("PropertyNo", proNum1);
                        }

                    }
                    if (chiefData[0].PropertyChiefDeptKeyId == chiefData[1].PropertyChiefDeptKeyId && chiefData[0].PropertyChiefKeyId == chiefData[1].PropertyChiefKeyId) {
                        tempChiefOption += '<option value="' + chiefData[0].PropertyChiefKeyId + ',' + chiefData[0].PropertyChiefDeptKeyId + '">' + chiefData[0].PropertyChief + ' ' + chiefData[0].PropertyChiefDept + '</option>';
                    } else {
                        for (var i = 0; i < chiefData.length; i++) {
                            tempChiefOption += '<option value="' + chiefData[i].PropertyChiefKeyId + ',' + chiefData[i].PropertyChiefDeptKeyId + '">' + chiefData[i].PropertyChief + ' ' + chiefData[i].PropertyChiefDept + '</option>';
                        }
                    }


                    pageNewEstateDetail.dialogMergeHouse();
                } else {
                    pageNewEstateDetail.tempChiefFunc();
                }
            });
        };
        pageNewEstateDetail.tempChiefFunc();

        pageNewEstateDetail.dialogMergeHouse = function () {
            $.dialog({
                id: "dialogMergeHouse",
                title: "合并房间资料",
                lock: true,
                background: "#808080",
                opacity: 0.87,
                content: '<span id="spanMergeHouse">' + $("#divMergeHouse").html() + '</span>',
                init: function () {
                    var $tempSpanOriginHouse = $("#spanMergeHouse #spanOriginHouse"), $tempSpanTarget = $("#spanMergeHouse #spanTarget"), tempBtnSubmit = $("#spanMergeHouse input[btn-submit=1]");
                    $("#OriginBuildingKeyId").val($("#hidOriginBuildingKeyId").val());
                    $("#spanMergeHouse [property-chief=1]").html(tempChiefOption);
                    tempBtnSubmit.removeClass("btn-gray").addClass("btn-red");

                    var orginHousePropertyNo = $(objModel[0]).data("PropertyNo");
                    $tempSpanOriginHouse.html($(objModel[0]).attr("house-no") + "[" + orginHousePropertyNo + "]");
                    $tempSpanOriginHouse.attr("sub-keyid", $(objModel[0]).attr("keyid"));
                    var targetPropertyNo = $(objModel[1]).data("PropertyNo");
                    $tempSpanTarget.html($(objModel[1]).attr("house-no") + "[" + targetPropertyNo + "]");
                    $tempSpanTarget.attr("sub-keyid", $(objModel[1]).attr("keyid"));

                    $("#btnTransposition").unbind("click");
                    $("#btnTransposition").bind("click", function () {
                        var tempHouseNo = $tempSpanOriginHouse.html(), tempSubKeyId = $tempSpanOriginHouse.attr("sub-keyid");
                        $tempSpanOriginHouse.html($tempSpanTarget.html());
                        $tempSpanOriginHouse.attr("sub-keyid", $tempSpanTarget.attr("sub-keyid"));
                        $tempSpanTarget.html(tempHouseNo);
                        $tempSpanTarget.attr("sub-keyid", tempSubKeyId);
                    });

                    tempBtnSubmit.click(function () {
                        if (tempBtnSubmit.hasClass("btn-red")) {
                            var tempTargetKeyIds = $("#spanMergeHouse #OriginBuildingKeyId").val(), tempArray = $("#spanMergeHouse [property-chief=1]").val().split(",");

                            var reqData = {
                                "OriginBuildingKeyId": tempTargetKeyIds,
                                "OriginHouseKeyId": $("#spanMergeHouse #spanOriginHouse").attr("sub-keyid"),
                                "TargetHouseKeyId": $("#spanMergeHouse #spanTarget").attr("sub-keyid"),
                                "IsMergeFollow": $("#spanMergeHouse input[name=IsMergeFollow]").attr("checked") == undefined ? false : true,
                                "IsMergeContact": $("#spanMergeHouse input[name=IsMergeContact]").attr("checked") == undefined ? false : true,
                                "IsMergeLog": $("#spanMergeHouse input[name=IsMergeLog]").attr("checked") == undefined ? false : true,
                                "PropertyChiefKeyId": tempArray[0],
                                "PropertyChiefDeptKeyId": tempArray[1]

                            };
                            other.buttonDisable(tempBtnSubmit);
                            $.AjaxAgency("/estate/merge-house", reqData, function (data) {
                                if (data == "ok") {
                                    $.OKDialogAgency('<center>合并成功！</center>', '提示', function () {
                                        window.location.href = window.location.href.split("#")[0];
                                    }, function () {
                                        window.location.href = window.location.href.split("#")[0];
                                    });

                                    art.dialog.get('dialogMergeHouse').close();

                                } else {
                                    $.dialog({
                                        lock: true,
                                        background: "#808080",
                                        opacity: 0.87,
                                        content: '<center>' + data + '</center>',
                                        cancel: function () { }
                                    });
                                }
                                other.buttonStart(tempBtnSubmit);
                            });
                        }
                    });

                }
            });
        };

    });
};

//获取修改房间信息
pageNewEstateDetail.getHouseInfo = function (ele) {
    if ($(ele).attr("disabled")) return;
    var keyId = $(ele).attr("keyid");
    var buildingKeyId = $(ele).attr("building-keyid");
    var buildingTypeCode = $(ele).attr("building-type-code");
    var roomNoRuleItemValue = $(ele).attr("roomNoRuleItemValue");
    var isBanUpdate = $(ele).attr("is-ban-update");
    var firstFloor = $("#btnAddHouse").attr("first-floor");
    var reqData = {
        "KeyId": keyId,
        "BuildingKeyId": buildingKeyId,
        "IsBanUpdate": isBanUpdate
    };
    $.AjaxAgency("/estate/find-house-for-edit", reqData, function (data) {
        if (data.indexOf("#error:") == -1) {
            $.dialog({
                id: "dialogEditHouseInfo",
                lock: true,
                title: "编辑房间",
              
                init: function () {
                    //表单验证
                    $("#editRoomForm").find("#txtHouseNo").bind("blur", function () {
                        $(this).removeClass("checkError").next(".wrong").remove();
                    });

                    $("#editRoomForm input[start-floor=1]").removeClass("checkError").next("span[class=wrong]").remove();
                    if ($("#editRoomForm input[start-floor=1]").next(".wrong").length <= 0 && firstFloor.length > 0 && parseInt($("#editRoomForm input[start-floor=1]").val()) < parseInt(firstFloor)) {
                        var $TempCurrentEleTxt = $("#editRoomForm input[start-floor=1]");
                        $TempCurrentEleTxt.addClass("checkError").after(agencyVerify.greatErrorHtml($TempCurrentEleTxt, "楼层不能小于" + firstFloor + "！"));
                    }

                    agencyVerify.notNullInput("#editRoomForm", "#editRoomForm input[notnull=1],select[notnull=1]", false, "blur");
                    $("#editRoomForm input[notnull=1]").blur();
                    agencyVerify.nonnegativeIntInput("#editRoomForm input[isint=1]", false);
                    agencyVerify.nonnegativeInput("#editRoomForm input[isfloat=1]", false);
                    agencyVerify.zhengFuIntInput("#editRoomForm input[iszhengfu=1]", true);
                    $("#editRoomForm input[start-floor=1]").focus(function () {
                        $(this).removeClass("checkError").next("span[class=wrong]").remove();
                    }).blur(function () {
                        if ($(this).next(".wrong").length <= 0 && firstFloor.length > 0 && parseInt($(this).val()) < parseInt(firstFloor)) {
                            var $TempCurrentEleTxt = $(this);
                            $TempCurrentEleTxt.addClass("checkError").after(agencyVerify.greatErrorHtml($TempCurrentEleTxt, "楼层不能小于" + firstFloor + "！"));
                        }
                    });



                    if (buildingTypeCode == "10") {
                        //房号规则验证
                        agencyVerify.regexCheck(null, "#editRoomForm #txtHouseNo", eval("/" + roomNoRuleItemValue + "/"), "房号不正确", false, "blur", function () {
                            if ($("#editRoomForm :checkbox[name=IsSpecialHouseNo]").get(0).checked) {
                                return false;
                            } else {
                                return true;
                            }
                        });
                        $("#editRoomForm :checkbox[name=IsSpecialHouseNo]").unbind("click");
                        $("#editRoomForm :checkbox[name=IsSpecialHouseNo]").bind("click", function () {
                            $("#editRoomForm #txtHouseNo").blur();
                        });
                    }
                    $("#editRoomForm").find("#txtHouseNo").bind("blur", { "IsAdd": false, "BuildingKeyId": buildingKeyId, "KeyId": keyId }, pageNewEstateDetail.checkHouseNo);

                    $("#btnHouseEditSubmit").click(function () {
                        if ($("#editRoomForm").find(".wrong").length > 0) {
                            return;
                        }
                        var thisbtnobj = "#btnHouseEditSubmit";
                        $(thisbtnobj).attr("disabled", "disabled").removeClass("btn-red").addClass("btn-gray");
                        $(thisbtnobj).attr("temp-value", $(thisbtnobj).val());
                        $(thisbtnobj).val("处理中…");

                        $("#editRoomForm").submit();
                    });
                },
                content: '<center>' + data + '</center>'
            });
        } else {
            $.dialog({
                lock: true,
                background: "#808080",
                opacity: 0.87,
                content: '<center>' + data + '</center>',
                cancel: function () { }
            });
        }
    });
};

//编辑房间成功方法
pageNewEstateDetail.editHouseSuccess = function (data) {
    if (data == "ok") {
        $.dialog({
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: '<center>编辑成功！</center>',
        }).time(1000);

        art.dialog.get("dialogEditHouseInfo").close();
        //window.location.href = window.location.href.split("#")[0];
    } else {
        $.dialog({
            lock: true,
            background: "#808080",
            opacity: 0.87,
            content: '<center>' + data + '</center>'
        });
        var thisbtnobj = "#btnHouseEditSubmit";
        $(thisbtnobj).removeAttr("disabled").removeClass("btn-gray").addClass("btn-red");
        $(thisbtnobj).val($(thisbtnobj).attr("temp-value"));
    }
};

//批量解锁
pageNewEstateDetail.batchCancelBanOperationBuilding = function () {
    var objModel = other.checkCount(true, "#ajaxPages input[class=btnValues]:checked", "请选择信息！", "请选择信息！");
    if (objModel == false) {
        return false;
    }
    var actModel = other.checkCount(true, "#ulBatchSetItemCancel input:checked", "请选择操作项！", "选择操作项！"/*回掉函数参数*/);
    if (actModel == false) {
        return false;
    }
    var tempKeyIds = "";
    $("#ajaxPages input[class=btnValues]:checked").each(function () {
        tempKeyIds += $(this).attr("keyid") + ",";
    });
    tempKeyIds = tempKeyIds.substring(0, tempKeyIds.length - 1);
    var banOperationType = "";
    $("#ulBatchSetItemCancel input[type=checkbox]:checked").each(function () {
        banOperationType += $(this).attr("banoperationtype") + ",";
    });
    banOperationType = banOperationType.substring(0, banOperationType.length - 1);
    var isBan = false;
    var operationvalue = "";
    $("#ulBatchSetItemCancel input[type=checkbox]:checked").each(function () {
        operationvalue += $(this).val() + ",";
    });
    operationvalue = operationvalue.substring(0, operationvalue.length - 1);
    //批量设置弹框
    $.dialog({
        id: "dialogBanOperationBuilding",
        title: "批量设置",
        lock: true,
        background: "#808080",
        opacity: 0.87,
        content: '<center>请确认将所选栋座设置为【' + operationvalue + '】当前栋座下的房源？</center>',
        ok: function () {
            var reqData = {
                "BuildingKeyIds": tempKeyIds,
                "BanOperationType": banOperationType,
                "IsBan": isBan
            };
            $.AjaxAgency("/estate/batchset-ban-operation", reqData, function (data) {
                if (data == "ok") {
                    $.OKDialogAgency(operationvalue + "成功！", "提示", function () {
                        window.location.href = window.location.href.split("#")[0];
                    }, function () {
                        window.location.href = window.location.href.split("#")[0];
                    });

                    art.dialog.get("dialogBanOperationBuilding").close();

                } else {
                    $.dialog({
                        lock: true,
                        background: "#808080",
                        opacity: 0.87,
                        content: '<center>' + data + '</center>',
                        cancel: function () { }
                    });
                }
            });
            return false;
        },
        cancel: true
    });

};


//批量锁定
pageNewEstateDetail.batchSetBanOperationBuilding = function () {
    var objModel = other.checkCount(true, "#ajaxPages input[class=btnValues]:checked", "请选择信息！", "请选择信息！");
    if (objModel == false) {
        return false;
    }
    var actModel = other.checkCount(true, "#ulBatchSetItem input:checked", "请选择操作项！", "选择操作项！"/*回掉函数参数*/);
    if (actModel == false) {
        return false;
    }
    var tempKeyIds = "";
    $("#ajaxPages input[class=btnValues]:checked").each(function () {
        tempKeyIds += $(this).attr("keyid") + ",";
    });
    tempKeyIds = tempKeyIds.substring(0, tempKeyIds.length - 1);
    var banOperationType = "";
    $("#ulBatchSetItem input[type=checkbox]:checked").each(function () {
        banOperationType += $(this).attr("banoperationtype") + ",";
    });
    banOperationType = banOperationType.substring(0, banOperationType.length - 1);
    var isBan = true;
    var operationvalue = "";
    $("#ulBatchSetItem input[type=checkbox]:checked").each(function () {
        operationvalue += $(this).val() + ",";
    });
    operationvalue = operationvalue.substring(0, operationvalue.length - 1);
    //批量设置弹框
    $.dialog({
        id: "dialogBanOperationBuilding",
        title: "批量设置",
        lock: true,
        background: "#808080",
        opacity: 0.87,
        content: '<center>请确认将所选栋座设置为【' + operationvalue + '】当前栋座下的房源？</center>',
        ok: function () {
            var reqData = {
                "BuildingKeyIds": tempKeyIds,
                "BanOperationType": banOperationType,
                "IsBan": isBan
            };
            $.AjaxAgency("/estate/batchset-ban-operation", reqData, function (data) {
                if (data == "ok") {
                    $.OKDialogAgency(operationvalue + "成功！", "提示", function () {
                        window.location.href = window.location.href.split("#")[0];
                    }, function () {
                        window.location.href = window.location.href.split("#")[0];
                    });

                    art.dialog.get("dialogBanOperationBuilding").close();

                } else {
                    $.dialog({
                        lock: true,
                        background: "#808080",
                        opacity: 0.87,
                        content: '<center>' + data + '</center>',
                        cancel: function () { }
                    });
                }
            });
            return false;
        },
        cancel: true
    });

};

//批量设置
pageNewEstateDetail.banOperationBuilding = function (ele) {
    var objModel = other.checkCount(true, "#ajaxPages input[class=btnValues]:checked", "请选择信息！", "选择信息必须唯一！");
    if (objModel == false) {
        return false;
    }
    var tempKeyIds = "";
    $("#ajaxPages input[class=btnValues]:checked").each(function () {
        tempKeyIds += $(this).attr("keyid") + ",";
    });
    tempKeyIds = tempKeyIds.substring(0, tempKeyIds.length - 1);

    var banOperationType = $(ele).attr("banOperationType");
    var isBan = $(ele).attr("isBan");
    //批量设置弹框
    $.dialog({
        id: "dialogBanOperationBuilding",
        title: "批量设置",
        lock: true,
        background: "#808080",
        opacity: 0.87,
        content: '<center>请确认将所选栋座设置为【' + $(ele).text() + '】当前栋座下的房源？</center>',
        ok: function () {
            var reqData = {
                "BuildingKeyIds": tempKeyIds,
                "BanOperationType": banOperationType,
                "IsBan": !!isBan
            };
            $.AjaxAgency("/estate/batch-ban-operation", reqData, function (data) {
                if (data == "ok") {
                    $.OKDialogAgency($(ele).text() + "成功！", "提示", function () {
                        window.location.href = window.location.href.split("#")[0];
                    }, function () {
                        window.location.href = window.location.href.split("#")[0];
                    });

                    art.dialog.get("dialogBanOperationBuilding").close();

                } else {
                    $.dialog({
                        lock: true,
                        background: "#808080",
                        opacity: 0.87,
                        content: '<center>' + data + '</center>',
                        cancel: function () { }
                    });
                }
            });
            return false;
        },
        cancel: true
    });
};

pageNewEstateDetail.exporHouseEdit = function () {
    //导出栋座房间
    $("#btnExport").unbind("click");
    $("#btnExport").bind("click", function () {
        var tempNext = true;
        $("#btnExport").each(function (index, domEle) {
            if ($(domEle).attr("is-open") == "true") {
                tempNext = false;
                return false;
            }
        });

        if (!tempNext) {
            $.dialog({
                lock: true,
                background: "#808080",
                opacity: 0.87,
                content: '<center>请等待上次导出成功或尝试再次导出！</center>',
                cancel: function () { }
            });
            return false;
        }

        var $CurrentProcessEle = $(this);
        var estateKeyId = $CurrentProcessEle.attr("building-keyid");

        var url = "/estate/export-house-edit";
        var reqData = {
            "EstateKeyId": estateKeyId
        };
        $CurrentProcessEle.attr("is-open", "true");
        $.AjaxAgency(url, reqData, function (data) { 
            var msg = "";
            if (data.flag == true) {

                window.location.href = data.data;
            } else {
                if (data.flag == false) {
                    msg = data.data;
                } else {
                    msg = data;
                }
                $.dialog({
                    lock: true,
                    background: "#808080",
                    opacity: 0.87,
                    content: msg,
                    cancel: function () { }
                });
            }
            $CurrentProcessEle.attr("is-open", "false");
        });
    });
}

var importEestateSWFU;
pageNewEstateDetail.uploadHouse = function () {
    //导入房间数据
    if ($("#btnImportHouse").length > 0) {


    }
}
pageNewEstateDetail.destory = function () {
    if (importEestateSWFU == null || importEestateSWFU == undefined)
        return;
    importEestateSWFU.destroy();
}


pageNewEstateDetail.EstateRoom = {
    init: function (obj, pathObj) {
        if (obj == null || obj == undefined) obj = $("#btnImportHouse");

        if (obj.length > 0) {
            if (pathObj == null || pathObj == undefined)
                pathObj = $("#uploadPath");
            this.uploadObj(pathObj);
        }
    },
    roomsObj: null,
    destoryx: function () {
        if (this.roomsObj == null || this.roomsObj == undefined) return;
        this.roomsObj.destroy();
    },
    uploadObj: function (pathObj) {   //pathObj =  $("#uploadPath");

        this.roomsObj = new SWFUpload({
            flash_url: "/Scripts/PageHelper/swfupload1.swf",
            upload_url: pathObj.val(),
            post_params: {},
            file_size_limit: "2 MB",
            file_types: "*.xlsx;*.xls",
            file_types_description: "2003 excel",
            file_upload_limit: 20,
            file_queue_limit: 20,
            custom_settings: {
                progressTarget: "fsUploadProgress"
            },
            debug: false,
            // Button settings
            button_disabled: false,
            button_width: "30",
            button_height: "20",
            button_placeholder_id: "btnImportHouse",
            button_cursor: SWFUpload.CURSOR.HAND,
            button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
            button_text: '<span class="cleanData">导入</span>',
            button_text_style: ".cleanData{color:#1f73f0;padding-top:5px;padding-botton:4px;}",

            file_queued_handler: fileQueued,
            file_queue_error_handler: fileQueueError,
            file_dialog_complete_handler: fileDialogComplete,
            upload_error_handler: uploadError,
            upload_success_handler: this.uploadSuccess,
            upload_complete_handler: uploadComplete,
            queue_complete_handler: queueComplete,	// Queue plugin event
            upload_start_handler: uploadStart
        });

    },
    uploadSuccess: function (file, serverData) {
        try {
            $("#spanFlashStauts").show();
            //$("#spanFlashStauts").show();
            //alert("befor ok");
            //var progress = new FileProgress(file, this.customSettings.progressTarget);
            //progress.setComplete();
            //progress.setStatus("Complete.");
            //progress.toggleCancel(false);
            //alert("Ok");
            //return false; 

            $.AjaxAgency("/estate/check-import-update-house", { "uploadURL": other.getFullPhotoPath($("#hidImageDownloadUrl").val(), serverData) }, function (data) {
                if (data != "ok") {
                    $.DialogAgency(data, "提示");
                    $("#spanFlashStauts").hide();
                }
                else {
                    $.OKCancelDialogAgency("<center>数据校验通过，请确认是否继续（不可逆）导入?</center>", "提示", function () { }, function () {

                        $.AjaxAgency("/estate/import-house", { "uploadURL": other.getFullPhotoPath($("#hidImageDownloadUrl").val(), serverData) }, function (data) {
                            if (data == "ok") {
                                $.DialogAgency('<center>导入成功！</center>', "提示", function () {

                                    $("#spanFlashStauts").hide();
                                });
                                window.location.href = window.location.href.split("#")[0];
                            } else if (data.indexOf("#error:") != -1) {
                                $.DialogAgency(data, "提示");
                                $("#spanFlashStauts").hide();
                            } else {
                                $.DialogAgency(data, "导入房间数据错误");
                                $("#spanFlashStauts").hide();
                            }

                            $("#spanFlashStauts").hide();
                        });
                    }, function () { $("#spanFlashStauts").hide(); });



                }


            });
        } catch (ex) {
            this.debug(ex);
        }
    }
};

//房号产证名
pageNewEstateDetail.addHouseRightNames = function () {
    var spanEstateAlias = $("#divDelinfo").find(".spanEstateAlias");
    if (spanEstateAlias.length >= 4) {
        $.OKDialogAgency('<center>房号产证名数量不能大于5！</center>');
        return;

    }
    $("#divDelinfo").append('<span class="spanEstateAlias mt10 l" style="height:26px;margin-right:9px;"><strong class="public w73">房号产证名：</strong><input type="text" class="ipt w200" name="HouseRightName"  maxlength="100"/><i class="delinfo" onclick="$(this).parent().remove();" title="删除房号产权名"></i></span>');
};

pageNewEstateDetail.checkIsDoubleHouse = function () {
    if ($("#ckbIsDoubleHouse").attr("checked") == "checked") {
        $("#addHouseRightName").css("display", "inline-block");

    } else {
        $("#addHouseRightName").css("display", "none");
        $("#divDelinfo").empty();
    }

};
